package config;

import corewarsxxi.logic.Core;
import corewarsxxi.logic.MemoryArray;
import java.io.Serializable;

/**
 * Contains configuration about the Core.
 * Can be stored in a file.
 * 
 * @version 1.0
 * @see     corewarsxxi.logic.Core
 * @author  Luís Fonseca, ei10139 @ FEUP
 */
public final class CoreConfig implements Serializable
{
    private int coreSize;
    private int maxCycles;
    private int minDistance;
    private int warriorMaxInstructions;

    /**
     * Constructor for the CoreConfig which should contain all the data upfront.
     * @param coreSize  the size of Memory Array
     * @param maxCycles the number of cycles which can be performed per simulation
     * @param minDistance   the minimum distance bewteen two warriors
     * @param warriorMaxInstructions    the number of maximum instructions that a warrior can have
     */
    public CoreConfig(int coreSize, int maxCycles, int minDistance, int warriorMaxInstructions)
    {
        this.coreSize = coreSize;
        setMaxCycles(maxCycles);
        setMinDistance(minDistance);
        setWarriorMaxInstructions(warriorMaxInstructions);
    }

    /**
     * @return the coreSize
     */
    public int getCoreSize() {
        return coreSize;
    }

    /**
     * @param coreSize the coreSize to be set
     */
    public void setCoreSize(int coreSize) {
        if(coreSize < 0)
            return;
        
        this.coreSize = coreSize;
        Core.getInstance().memArray = new MemoryArray(coreSize);
    }

    /**
     * @return the maxCycles
     */
    public int getMaxCycles() {
        return maxCycles;
    }

    /**
     * @param maxCycles the maxCycles to be set
     */
    public void setMaxCycles(int maxCycles) {
        this.maxCycles = maxCycles;
    }

    /**
     * @return the minDistance
     */
    public int getMinDistance() {
        return minDistance;
    }

    /**
     * @param minDistance the minDistance to be set
     */
    public void setMinDistance(int minDistance) {
        this.minDistance = minDistance;
    }

    /**
     * @return the warriorMaxInstructions
     */
    public int getWarriorMaxInstructions() {
        return warriorMaxInstructions;
    }

    /**
     * @param warriorMaxInstructions the warriorMaxInstructions to be set
     */
    public void setWarriorMaxInstructions(int warriorMaxInstructions) {
        if(getMinDistance() < warriorMaxInstructions);
            setMinDistance(warriorMaxInstructions);
            
        this.warriorMaxInstructions = warriorMaxInstructions;
    }
}
